<template>
  <div class="received-bottles-page">
    <div class="page-header">
      <h2>收到的瓶子</h2>
      <p>这里展示你捞到的漂流瓶</p>
    </div>

    <div class="bottles-container" v-if="receivedBottles.length > 0">
      <div
          v-for="bottle in receivedBottles"
          :key="bottle.id"
          class="bottle-card"
      >
        <div class="bottle-header">
          <img :src="bottle.avatar" :alt="bottle.username" class="user-avatar" />
          <div class="user-info">
            <h3 class="username">{{ bottle.username }}</h3>
            <p class="time">{{ bottle.timeAgo }}</p>
          </div>
        </div>

        <div class="bottle-content">
          <p>{{ bottle.message }}</p>
          <div class="tags">
            <span v-for="tag in bottle.tags" :key="tag" class="tag">{{ tag }}</span>
          </div>
        </div>

        <div class="bottle-footer">
          <div class="bottle-stats">
            <span class="likes">❤️ {{ bottle.likes }}</span>
            <span class="distance">📍 {{ bottle.location }}</span>
          </div>
          <div class="bottle-actions">
            <button class="action-btn like-btn" @click="likeBottle(bottle.id)">
              {{ bottle.isLiked ? '取消赞' : '点赞' }}
            </button>
            <button class="action-btn reply-btn">回复</button>
          </div>
        </div>
      </div>
    </div>

    <div class="empty-state" v-else>
      <div class="empty-icon">📭</div>
      <h3>还没有收到瓶子</h3>
      <p>快去捞瓶子吧，看看别人分享了什么有趣的内容！</p>
      <button class="primary-btn" @click="$router.push('/drift-bottle')">
        去捞瓶子
      </button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import avatarChenyundong from '@/assets/images/avatar_chenyundong.png'
import avatarLiyujia from '@/assets/images/avatar_liyujia.png'
import avatarWangqixing from '@/assets/images/avatar_wangqixing.png'

// 模拟收到的瓶子数据
const receivedBottles = ref([])

// 初始化数据
const initializeReceivedBottles = () => {
  const mockData = [
    {
      id: 1,
      username: '跑步达人',
      avatar: avatarChenyundong,
      message: '今天跑了10公里，感觉超棒！谁要一起晨跑？',
      tags: ['#跑步', '#晨练'],
      likes: 12,
      isLiked: false,
      timeAgo: '2小时前',
      location: '中央公园'
    },
    {
      id: 2,
      username: '瑜伽爱好者',
      avatar: avatarLiyujia,
      message: '瑜伽练习第30天，身心都得到了放松～',
      tags: ['#瑜伽', '#冥想'],
      likes: 8,
      isLiked: true,
      timeAgo: '1天前',
      location: '瑜伽馆'
    },
    {
      id: 3,
      username: '游泳健将',
      avatar: avatarWangqixing,
      message: '刚学会游泳的自由泳，好有成就感！',
      tags: ['#游泳', '#自由泳'],
      likes: 15,
      isLiked: false,
      timeAgo: '3天前',
      location: '市游泳馆'
    }
  ]

  receivedBottles.value = mockData
}

// 点赞功能
const likeBottle = (id) => {
  const bottle = receivedBottles.value.find(b => b.id === id)
  if (bottle) {
    bottle.isLiked = !bottle.isLiked
    bottle.likes += bottle.isLiked ? 1 : -1
  }
}

onMounted(() => {
  initializeReceivedBottles()

  // 从本地存储加载收到的瓶子数据
  try {
    const stored = localStorage.getItem('drift-bottle-received')
    if (stored) {
      const parsed = JSON.parse(stored)
      receivedBottles.value = parsed
    }
  } catch (error) {
    console.error('加载收到的瓶子数据失败:', error)
  }
})
</script>

<style scoped>
.received-bottles-page {
  padding: 20px;
  background: linear-gradient(135deg, #2ECC71 0%, #27AE60 25%, #16A085 50%, #1ABC9C 75%, #2ECC71 100%);
  min-height: 100vh;
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
}

.page-header h2 {
  font-size: 28px;
  margin-bottom: 10px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.page-header p {
  font-size: 16px;
  opacity: 0.9;
}

.bottles-container {
  display: grid;
  gap: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.bottle-card {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.bottle-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
}

.bottle-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}

.user-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 15px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.user-info h3 {
  margin: 0 0 5px 0;
  font-size: 18px;
  font-weight: 600;
}

.user-info p {
  margin: 0;
  font-size: 14px;
  opacity: 0.8;
}

.bottle-content p {
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 15px;
  color: rgba(255, 255, 255, 0.9);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tag {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.bottle-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 16px;
}

.bottle-stats {
  display: flex;
  gap: 15px;
}

.bottle-stats span {
  font-size: 14px;
  opacity: 0.9;
}

.bottle-actions {
  display: flex;
  gap: 10px;
}

.action-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  padding: 8px 15px;
  border-radius: 20px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  backdrop-filter: blur(10px);
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.like-btn.liked {
  background: #ff6b6b;
}

.like-btn.liked:hover {
  background: #ff5252;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: white;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state h3 {
  margin: 0 0 8px 0;
  font-size: 20px;
  font-weight: 600;
}

.empty-state p {
  margin: 0 0 24px 0;
  color: rgba(255, 255, 255, 0.7);
}

.primary-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 24px;
  padding: 12px 24px;
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.primary-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .received-bottles-page {
    padding: 16px;
  }

  .bottles-container {
    gap: 16px;
  }

  .bottle-card {
    padding: 16px;
  }

  .bottle-header {
    margin-bottom: 12px;
  }

  .user-avatar {
    width: 40px;
    height: 40px;
  }

  .user-info h3 {
    font-size: 16px;
  }

  .bottle-content p {
    font-size: 14px;
    margin-bottom: 12px;
  }

  .tags {
    margin-bottom: 12px;
  }

  .bottle-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .bottle-stats {
    width: 100%;
  }

  .bottle-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .action-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
}
</style>